import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import store from '@/store'

Vue.use(VueRouter)

const routes = [

  // {
  //   path: '/',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/HomeView.vue')
  // },
  {
    path: '/',
    name: 'patientList',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/PatientList/index.vue')
  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login/index.vue')
  },
 
]

const router = new VueRouter({
  mode:'hash',
  routes
})
const whiteUrlList = ['/login']

router.beforeEach((to,from,next)=>{
  //1.login、register 需要验证吗？ = > 白名单 放行
 
  if(whiteUrlList.includes(to.path)){
    return next();
  }
  if(store.getters.loginInfo){
     return next(); 
  }else
  {
      //3.没有登录-去登录页面
   return next('/login?redirect='+to.path);
  }

  return next();
})


export default router
